﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Diagnostics;
using System.Windows.Threading;


namespace TFSDeplyFrontEnd
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class DeploySplash : Window
    {
        DispatcherTimer _launchTimer;

        public DeploySplash()
        {
            InitializeComponent();
            _launchTimer = new DispatcherTimer();
            _launchTimer.Interval = new TimeSpan(0, 0, 1);
            _launchTimer.Tick += new EventHandler(StartInstall);
            _launchTimer.Start();
        }

        private void StartInstall(object sender, EventArgs e)
        {
            _launchTimer.Stop();
            InstallSoftware();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            InstallSoftware();
        }

        void InstallSoftware()
        {
            const string BASE_PATH = @"C:\Program Files\Process Dashboard\";
            const string TEMPLATE_PATH = BASE_PATH + @"\Templates";
            const string EXE = @".\TFSGetFiles.exe";
            const string JAR = @".\TFSLOC.jar";
            const string XML = @".\ProjectSpecificLanguageFilter-template.xml";

            Directory.CreateDirectory(TEMPLATE_PATH);

            File.Copy(JAR, BASE_PATH + JAR, true);
            File.Copy(EXE, BASE_PATH + EXE, true);
            File.Copy(XML, TEMPLATE_PATH + XML, true);

            if (File.Exists(BASE_PATH + JAR))
                PDPtextBox.Text = "Present";
            else
                PDPtextBox.Text = "Missing";

            if (File.Exists(BASE_PATH + EXE))
                TFSCLTtextBox.Text = FileVersionInfo.GetVersionInfo(BASE_PATH + EXE).ProductVersion.ToString();
            else
                TFSCLTtextBox.Text = "Missing";


            if (File.Exists(TEMPLATE_PATH + XML))
                TemplatetextBox.Text = "Present";
            else
                TemplatetextBox.Text = "Missing";

        }

    }

}
